home *** CD-ROM | disk | FTP | other *** search
File List | 1987-07-14 | 3.5 KB | 123 lines |
- '
- ' LISTBOX
- ' by Gary Wren
- '
- ' This routine will display a list, draw an appropriately sized box around it
- ' and allow the user to use the mouse to select an item. Merge it with your
- ' own programs and use it insted of "input" commands.
- '
- ' Experiment with lists of varying sizes by changing Max_item% below (0-29).
- ' This routine uses option base 0, so the first item is item$(0).
- '
- ' WARNING: Turn the sound off to avoid a continous bell.
- ' *******************************
- ' Put these three lines where appropriate in your program
- Clr Column%,Ty%,Tx%,Mk%,Mx%,My%,Cancel
- Max_items%=18 ! You may have up to 30 items
- Dim Item$(Max_items%+1) ! Item$(x)=item in the list
- ' -------------
- ' This assigns letter names to the items so you can run the routine on its own.
- ' Fill Item$() with your own names in your program.
- Ch=97
- Repeat
- Inc K
- Item$(K)=Chr$(Ch)
- Inc Ch
- Until K=Max_items%+1
- ' ---------------------
- Gosub Listbox ! Don't forget this in your program!
- Pause 200 ! Delete these two lines
- Edit
- ' **********************************
- Procedure Listbox
- ' --------- display the list
- K=1
- X=30
- Y=50
- Deftext 1,0,0,6
- Repeat
- Text X-25,Y,K
- Text X,Y,Item$(K)
- Inc K
- Add Y,10
- If K=16
- Y=50
- Add X,150
- Endif
- Until K=Max_items%+2
- ' ------------------- draw a box around it
- Defline 1,4,0,0
- If X>150
- Box 1,40,X+125,194
- Else
- Box 1,40,X+125,((K-1)*10)+44
- Endif
- ' ------------------- draw a "Cancel" button
- Box 400,100,470,115
- Text 412,110,"Cancel"
- ' ------------- get the mouse position
- Do
- Clr Col%,Ty%,Tx%,Mk%,Mx%,My%
- Mx%=Mousex
- My%=Mousey
- Mk%=Mousek
- If Mk%=1
- Deftext 1,0,0,6
- Text Oldtx%-25,Oldy,Oldty%
- Text Oldtx%,Oldy,Item$(Oldty%)
- If Mx%>400 And Mx%<470 And My%>100 And My%<115
- Deftext 2,1,0,6
- Text 412,110,"Cancel"
- Deftext 1,0,0,6
- Cancel=1
- Endif
- Endif
- ' ---------------- determine the column and row selected
- If Mx%<=X+124 And My%=>40 And My%<195
- If Mx%<=155
- Tx%=30
- Column%=0
- Endif
- If Mx%>155 And Mx%<=329
- Tx%=180
- Column%=1
- Endif
- Ty%=(Int((My%-45)/10)+1)
- Y=40+(Ty%*10)
- If Column%=1 And Ty%>0 Then
- Add Ty%,15
- Endif
- ' ----------------
- If Ty%<Max_items%+2 And Ty%>0 And Ty%<>Oldty%
- Graphmode 1
- ' ----------- display a deselected item in white
- Deftext 1,0,0,6
- Text Oldtx%-25,Oldy,Oldty%
- Text Oldtx%,Oldy,Item$(Oldty%)
- '
- ' --------- display the selection in red
- Deftext 2,1,0,6
- Text Tx%-25,Y,Ty%
- Text Tx%,Y,Item$(Ty%)
- ' ----------
- Oldty%=Ty%
- Oldtx%=Tx%
- Oldcol%=Column%
- Oldy=Y
- Endif
- Endif
- Exit If (Mk%=1 And Ty%<Max_items%+2 And Ty%>0) Or Cancel=1
- Loop
- ' ---------------------- Display position and item selected
- If Cancel=1
- Goto Ret
- Endif
- Print At(50,2);String$(29," ")
- Print At(50,3);String$(29," ")
- Print At(50,2);"Row=";Ty%;"; Column x=";Tx%
- Print At(50,3);"Mouse x=";Mx%;"; Mouse y=";My%
- Print At(50,4);String$(29," ")
- Print At(50,4);"Choice= ";Ty%;". ";Item$(Ty%)
- Ret:
- Return
-